<script setup lang='ts'>
  import { onMounted, reactive } from 'vue';
  import { numberApi } from '@/api/controller';
  import { ElMessageBox } from 'element-plus';
  import { Toastloading, ToastSuccess, ToastWarning } from '@/utils/public';
  import Pagination from "@/components/Pagination/index.vue";
  import serachUserid from '@/components/serachUserid/index.vue';
  const action = reactive({
    total:0,
    list:[] as any[],
    EquipType:[] as any[],
    dateArr:[],
  })
  const listQuery = reactive({
    user_id:'',
    agent_type:'',
    page: 1,
    limit: 20,
  })
  const typeArr = [
    {type:1,text:'钻石兑换获得'},
    {type:2,text:'金币兑换获得'},
    {type:51,text:'转出扣除'},
    {type:52,text:'解除代理扣除'},
  ]
  const handleFilter = ()=>{
    listQuery.page = 1
    getList()
  }
  const resetQuery = ()=>{
    Object.assign(listQuery,{
      user_id:'',
      agent_type:'',
      page: 1,
      limit: 20,
    })
    action.dateArr = []
    getList()
  }
  const getList = async()=> {
    const loading = Toastloading()
    const res = await numberApi.agentLogList({
      ...listQuery,
      time_st:action.dateArr?.[0] || '',
      time_ed:action.dateArr?.[1] || '',
    })
    loading.close()
    const { data=[], total=0 } = res.data
    action.list = data
    action.total = total
  }
  onMounted(()=>{
    getList()
  })
</script>

<template>
  <div class="xm-content">
    <div class="xm-headTab">
      <div class="labelBox">
        <div class="labelItem">
          <div class="label">代理用户ID：</div>
          <serachUserid v-model:user_id="listQuery.user_id" />
        </div>
        <div class="labelItem">
          <div class="label">交易类型：</div>
          <el-select v-model="listQuery.agent_type" clearable placeholder="请选择交易类型">
            <el-option label="转出" :value="1" />
            <el-option label="兑换" :value="2" />
          </el-select>
        </div>
        <div class="labelItem">
          <div class="label">日期：</div>
          <el-date-picker
            v-model="action.dateArr"
            type="daterange"
            format="YYYY-MM-DD HH:mm:ss"
            value-format="YYYY-MM-DD HH:mm:ss"
            range-separator="至"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
          />
        </div>
        <div class="labelItem">
          <el-button type="primary" @click="handleFilter">查询</el-button>
          <el-button type="primary" @click="resetQuery">重置</el-button>
        </div>
      </div>
    </div>
    <el-table
      class="xm-main xm-TableCenter"
      :data="action.list"
      border>
      <el-table-column min-width="120" prop="stream_id" label="记录ID" />
      <el-table-column min-width="120" prop="user_id" label="代理用户ID" />
      <el-table-column min-width="120" sortable prop="diamond_value" label="用户钻石余额变化" />
      <el-table-column min-width="120" prop="diamond_desc" label="变动描述" />
      <el-table-column min-width="120" prop="diamond_type" label="类型">
        <template #default="scope">
          {{ typeArr.find(res=>res.type == scope.row.diamond_type)?.text || scope.row.diamond_type }}
        </template>
      </el-table-column>
<!--      <el-table-column min-width="120" prop="pay_type" label="数据类型">-->
<!--        <template #default="scope">-->
<!--          {{ ['','userId','钻石值','金币值'][scope.row.pay_type] }}-->
<!--        </template>-->
<!--      </el-table-column>-->
      <el-table-column min-width="120" prop="change_timestamp" label="时间" />
    </el-table>
    <Pagination v-show="action.total > 0" :total="action.total" v-model:page="listQuery.page"
      v-model:limit="listQuery.limit" @pagination="getList" />
  </div>
</template>
